home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.3 KB  |  365 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef BINDING_K
  15. #include "Binding.k"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef SELECTION_H
  31. #include "Selection.h"
  32. #endif
  33.  
  34. #ifndef SOM_ODFExamples_ODFTableEmbeddedFramesIterator_xh
  35. #include "SOMIter.xh"
  36. #endif
  37.  
  38. #ifndef LINKING_H
  39. #include "Linking.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. // ----- Part Layer -----
  47.  
  48. #ifndef FWFRAME_H
  49. #include "FWFrame.h"
  50. #endif
  51.  
  52. #ifndef FWABOUT_H
  53. #include "FWAbout.h"
  54. #endif
  55.  
  56. #ifndef FWFCTCLP_H
  57. #include "FWFctClp.h"
  58. #endif
  59.  
  60. #ifndef FWPRTITE_H
  61. #include "FWPrtIte.h"
  62. #endif
  63.  
  64. #ifndef FWDRCMD_H
  65. #include "FWDrCmd.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWACQUIR_H
  79. #include "FWAcquir.h"
  80. #endif
  81.  
  82. #ifndef FWEVENT_H
  83. #include "FWEvent.h"
  84. #endif
  85.  
  86. #ifndef FWMENU_H
  87. #include "FWMenu.h"
  88. #endif
  89.  
  90. #ifndef FWPOINT_H
  91. #include "FWPoint.h"
  92. #endif
  93.  
  94. #ifndef FWRECT_H
  95. #include "FWRect.h"
  96. #endif
  97.  
  98. #ifndef FWSUSINK_H
  99. #include "FWSUSink.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. #ifndef FWBARRAY_H
  107. #include "FWBArray.h"
  108. #endif
  109.  
  110. #ifndef FWCFMRES_H
  111. #include "FWCFMRes.h"
  112. #endif
  113.  
  114. // ----- Foundation Layer -----
  115.  
  116. #ifndef FWSTRING_H
  117. #include "FWString.h"
  118. #endif
  119.  
  120. #ifndef FWEXCDEF_H
  121. #include "FWExcDef.h"
  122. #endif
  123.  
  124. // ----- OpenDoc Includes -----
  125.  
  126. #ifndef FWODTYPS_H
  127. #include "FWODTyps.h"
  128. #endif
  129.  
  130. #ifndef SOM_ODArbitrator_xh
  131. #include <Arbitrat.xh>
  132. #endif
  133.  
  134. #ifndef SOM_ODMenuBar_xh
  135. #include <MenuBar.xh>
  136. #endif
  137.  
  138. #ifndef SOM_ODShape_xh
  139. #include <Shape.xh>
  140. #endif
  141.  
  142. #ifndef SOM_Module_OpenDoc_StdProps_defined
  143. #include <StdProps.xh>
  144. #endif
  145.  
  146. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  147. #include <StdTypes.xh>
  148. #endif
  149.  
  150. #ifndef SOM_ODStorageUnit_xh
  151. #include <StorageU.xh>
  152. #endif
  153.  
  154. #ifndef SOM_ODTransform_xh
  155. #include <Trnsform.xh>
  156. #endif
  157.  
  158. #ifndef SOM_ODSession_xh
  159. #include <ODSessn.xh>
  160. #endif
  161.  
  162. //========================================================================================
  163. // RunTime Info
  164. //========================================================================================
  165.  
  166. #ifdef FW_BUILD_MAC
  167. #pragma segment odfTable
  168. #endif
  169.  
  170. FW_DEFINE_AUTO(CTablePart)
  171.  
  172. //========================================================================================
  173. //    class CTablePart
  174. //========================================================================================
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CTablePart::CTablePart
  178. //----------------------------------------------------------------------------------------
  179.  
  180. CTablePart::CTablePart(ODPart* odPart) :
  181.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  182.     fTableLinkManager(NULL),
  183.     fPostCreated(false)
  184. {
  185.     FW_END_CONSTRUCTOR
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    CTablePart::~CTablePart
  190. //----------------------------------------------------------------------------------------
  191.  
  192. CTablePart::~CTablePart()
  193. {
  194.     FW_START_DESTRUCTOR
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    CTablePart::Initialize
  199. //----------------------------------------------------------------------------------------
  200.  
  201. void CTablePart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  202. {
  203.     // ----- Call Inherited Initialize -----
  204.     FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
  205.  
  206.     // ----- Register Presentation -----
  207.     fTablePresentation = RegisterPresentation(ev, 
  208.                                             kTablePresentation, 
  209.                                             true, 
  210.                                             kTableView, kTableView, 
  211.                                             FW_NEW(CTableSelection, (ev, this, fTableContent)));
  212.     
  213.     // ----- Build Table menu -----
  214. #ifdef FW_BUILD_WIN
  215.     // [HLX] Temporary embed menu for windows
  216.     WinAddEmbedMenu(ev, GetMenuBar(ev));
  217. #endif
  218.  
  219.     FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    CTablePart::NewFrame
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_CFrame* CTablePart::NewFrame(Environment* ev, 
  227.                                 ODFrame* odFrame, 
  228.                                 FW_CPresentation* presentation,
  229.                                 FW_Boolean fromStorage)
  230. {
  231.     FW_UNUSED(fromStorage);
  232.  
  233.     return FW_NEW(CTableFrame, (ev, odFrame, presentation, this, fTableContent));
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    CTablePart::NewPartContent
  238. //----------------------------------------------------------------------------------------
  239.  
  240. FW_CContent* CTablePart::NewPartContent(Environment* ev)
  241. {
  242.     fTableContent = FW_NEW(CTablePartContent, (ev, this));
  243.     return fTableContent;
  244. }
  245.  
  246. //========================================================
  247. // ADDITIONS FOR LINKING SUPPORT
  248. //========================================================
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    CTablePart::PartChanged
  252. //----------------------------------------------------------------------------------------
  253. void CTablePart::PartChanged(Environment* ev)
  254. {
  255.     fTablePresentation->ContentUpdated(ev);
  256.  
  257.     //--- Update affected link sources ---
  258.     fTableLinkManager->UpdateLinkSource(ev, kODUnknownUpdate);
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    CTablePart::DoAbout
  263. //----------------------------------------------------------------------------------------
  264.  
  265. FW_Handled CTablePart::DoAbout(Environment* ev)
  266. {
  267.     ::FW_About(ev, this, kAbout);
  268.     
  269.     return FW_kHandled;
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. //    CTablePart::ChangeFrameStatus
  274. //----------------------------------------------------------------------------------------
  275.  
  276. void CTablePart::ChangeFrameStatus(Environment* ev, const CCell& cell, ODLinkStatus newStatus)
  277. {
  278.     CTableProxy* proxy = fTableContent->CellToProxy(cell);
  279.     if (proxy)
  280.         proxy->ChangeLinkStatus(ev, newStatus);
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CTablePart::AboutToClearCell
  285. //----------------------------------------------------------------------------------------
  286. void CTablePart::AboutToClearCell(Environment* ev, const CCell& cell)
  287. {
  288.     //-- Break affected links --
  289.     fTableLinkManager->BreakExistingLinks(ev, cell);
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    CTablePart::ProxyMoved
  294. //----------------------------------------------------------------------------------------
  295. void CTablePart::ProxyMoved(Environment* ev,
  296.                             const CCell& fromCell,
  297.                             const CCell& toCell)
  298. {
  299.     //-- Adjust affected links --
  300.     fTableLinkManager->MoveExistingLinks(ev, fromCell, toCell);
  301. }
  302.  
  303. //----------------------------------------------------------------------------------------
  304. //    CTablePart::GetTableSelection
  305. //----------------------------------------------------------------------------------------
  306. CTableSelection* CTablePart::GetTableSelection(Environment* ev)
  307. {
  308.     return (CTableSelection*) fTablePresentation->GetSelection(ev);
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. //    CTablePart::NewLinkManager
  313. //----------------------------------------------------------------------------------------
  314.  
  315. FW_CLinkManager* CTablePart::NewLinkManager(Environment* ev)    // Override
  316. {
  317.     CTableLinkManager* linkMgr = FW_NEW (CTableLinkManager, (ev, this, fTableContent));
  318.     fTableLinkManager = linkMgr;
  319.     return linkMgr;
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    CTablePart::DoPostCreate
  324. //----------------------------------------------------------------------------------------
  325. void CTablePart::DoPostCreate(Environment* ev)
  326. {
  327.     // Perform "DoPostCreate"-type initialization:
  328.     //    1. Set the initial selection
  329.     //    2. Make sure that any subscribers that were just internalized get registered for automatic updates.
  330.  
  331.     if (!fPostCreated)    // do this only once!
  332.     {
  333.         // Register any link destinations that were just internalized.
  334.         fTableLinkManager->RegisterLinks(ev);
  335.  
  336.         fPostCreated = true;
  337.     }
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. //    CTablePart::FindValidTableFrame
  342. //----------------------------------------------------------------------------------------
  343. CTableFrame* CTablePart::FindValidTableFrame(Environment* ev, CTableFrame* frame1, CTableFrame* frame2)
  344. {
  345.     if (IsFrameValid(ev, frame1))
  346.         return frame1;
  347.     if (IsFrameValid(ev, frame2))
  348.         return frame2;
  349.     return NULL;
  350. }
  351.  
  352. //----------------------------------------------------------------------------------------
  353. //    CTablePart::IsFrameValid
  354. //----------------------------------------------------------------------------------------
  355. FW_Boolean CTablePart::IsFrameValid(Environment* ev, FW_CFrame* frame)
  356. {
  357.     FW_CPresentationFrameIterator it(ev, fTablePresentation);
  358.     for (FW_CFrame* aFrame = it.First(ev); it.IsNotComplete(ev); aFrame =  it.Next(ev))
  359.     {
  360.         if (aFrame == frame)    // frame is valid
  361.             return true;
  362.     }
  363.     return false;
  364. }
  365.